{block name="content"}
<div class="think-box-shadow">
    <div class="layui-bg-gray border-line border-radius-5 margin-bottom-15 padding-20">
        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <b>代理姓名：</b><b class="color-blue">{$agent.username|default=''}</b>
                    <span class="margin-left-5">{$agent.phone|default=''}</span>
                </div>
                <div class="layui-form-item">
                    <b>产品编号：</b><b>{$product.code|default=''}</b>
                </div>
                <div>
                    <b>产品名称：</b><b class="color-blue">{$product.name|default=''}</b>
                    <span class="margin-left-5">{$product_spec|show_goods_spec}</span>
                </div>
            </div>
            <div class="layui-col-xs6 sub-strong-blue">
                <div class="layui-form-item">
                    <span>累计入库<b class="margin-row-5">{$stock.stock_total+$stock.vir_total}</b>{$stock.product.unit|default=''}</span>
                </div>
                <div class="layui-form-item">
                    <span>累计出库<b class="margin-row-5">{$stock.sotck_used+$stock.vir_used}</b>{$stock.product.unit|default=''}</span>
                </div>
                <div>
                    <span>现有库存<b class="margin-row-5">{$stock.stock_total+$stock.vir_total-$stock.sotck_used-$stock.vir_used}</b> {$stock.product.unit|default=''}</span>
                </div>
            </div>
        </div>
    </div>
    <table id="StockData" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
</div>
<script>
    $(function () {
        var auid = parseInt('{$auid|default=""}');
        $('#StockData').layTable({
            even: true, height: 'full', loading: true,
            sort: {field: 'create_time', type: 'desc'},
            where: {
                auid: '{$auid|default=""}',
                product_code: '{$product_code|default=""}',
                product_spec: '{$product_spec|default=""}',
            },
            cols: [[
                {
                    field: 'auid', title: '操作类型', align: 'center', width: 120, templet: function (d) {
                        if (d.code.indexOf('RV') > -1) return '<b class="color-red">撤回</b>';
                        if (d.auid === auid) return '<b class="color-green">进货</b>';
                        if (d.xuid === auid) return '<b class="color-blue">出货</b>';
                        return d.auid;
                    }
                },
                {field: 'code', title: '出入库编号', minWidth: 160, sort: true, align: 'center'},
                {field: 'create_time', title: '操作时间', minWidth: 170, align: 'center', sort: true},
                {
                    field: 'num_used', title: '操作数量', align: 'right', width: 130, templet: function (d) {
                        return layui.laytpl('<span><b class="{{d.class}} font-s16 margin-right-5">{{d.step}} {{d.num}}</b> {{d.unit}}</span>').render({
                            num: d.num_used + d.vir_used,
                            step: d.auid === auid ? '+' : '-',
                            unit: '{$stock.product.unit|default=""}',
                            class: d.code.indexOf('RV') > -1 ? 'color-red' : (d.auid === auid ? 'color-green' : 'color-blue')
                        });
                    }
                },
            ]]
        });
    });
</script>
{/block}